package com.eas.biz.constants;

import java.util.HashMap;
import java.util.Map;

public enum UserTypeEnum {

    ADMIN(0), STUDENT(1), PARENT(2), TEACHER(3), COMMITTEE(4);

    private int value;

    private static volatile Map<Integer, UserTypeEnum> typeMap;

    private UserTypeEnum(int value) {
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public boolean equals(UserTypeEnum userType) {
        return userType != null && this.value == userType.getValue();
    }

    public static UserTypeEnum getUserType(int value) {
        return getTypeMap().get(Integer.valueOf(value));
    }

    private static Map<Integer, UserTypeEnum> getTypeMap() {
        if (typeMap == null) {
            typeMap = new HashMap<Integer, UserTypeEnum>();
            for (UserTypeEnum type : UserTypeEnum.values()) {
                typeMap.put(Integer.valueOf(type.getValue()), type);
            }
        }
        return typeMap;
    }
}
